package com.zhangck.bos2_0.Service.transit.Impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhangck.bos2_0.Service.transit.TransitInfoServices;
import com.zhangck.bos2_0.dao.WayBillQuickRepoistory;
import com.zhangck.bos2_0.dao.WayBillRepoistory;
import com.zhangck.bos2_0.dao.Transit.TransitInfoRepository;
import com.zhangck.bos2_0.index.indexRepository;

import cn.itcast.bos.domain.take_delivery.WayBill;
import cn.itcast.bos.domain.transit.TransitInfo;

/** 
* @author 上午茶
* @version 创建时间：2018年6月19日 下午3:54:34 
* 类说明 
*/
@Service
@Transactional
public class TransitInfoServicesImpl implements TransitInfoServices {

	@Autowired
	private TransitInfoRepository transitInfoRepository;
	
	@Autowired
	private WayBillQuickRepoistory WayBillQuickRepoistory;
	
	@Autowired
	private indexRepository indexRepository;
	
	@Override
	public void createTransitInfo(String wayBillIIds) {
			if (StringUtils.isNotBlank(wayBillIIds)) {
				String[] ids = wayBillIIds.split(",");
				for (String string : ids) {
					  WayBill wayBill = WayBillQuickRepoistory.findOne(Integer.parseInt(string));
					  if (wayBill.getSignStatus()==1) {
						  TransitInfo transitInfo = new TransitInfo();
						  transitInfo.setWayBill(wayBill);
						  transitInfo.setStatus("出入库中转");
						  transitInfoRepository.save(transitInfo);
						  
						  wayBill.setSignStatus(2);
						  
						  indexRepository.save(wayBill);
					  }
				}
			}
	}

	@Override
	public Page<TransitInfo> findPage(Pageable pageable) {
		return transitInfoRepository.findAll(pageable);
	}



	

}
